
package datasv.studentQuery_datasv;

import java.util.Date;

import data.datafactory.DatabaseOperator;
import po.StudentPO;
import resultmessage.StudentQueryRM;

public class AddStudent {
	public static void main(String[] args) {
		System.out.println(new AddStudent().addInSql(new StudentPO("001131011","test",new Date(1992,3,23),"001","software",2013)));
	}
	public StudentQueryRM addStudent(StudentPO po) {
		return addInSql(po);
	}
	private StudentQueryRM addInSql(StudentPO po){
		DatabaseOperator op=new DatabaseOperator("college"+po.getCollegeID());
		if(!op.ifDatabaseExist()||op.ifIDExist("student_list", po.getStudentID())){
			return StudentQueryRM.STUDENT_EXIST;
		}
		String[][] info={{"id",po.getStudentID()},{"name",po.getName()},{"collegeID",po.getCollegeID()},{"department",po.getDepartment()},{"birthday",Integer.toString(po.getBirthday().getYear())+"/"+Integer.toString(po.getBirthday().getMonth())+"/"+Integer.toString(po.getBirthday().getDate())},{"educateStartYear",Integer.toString(po.getEduStartYear())}};
		if(op.addOneRow(info, "student_list")){
			return StudentQueryRM.SUCCESS;
		}
		return StudentQueryRM.STUDENT_EXIST;
	}
}
